import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:"*",
    redirect:"/",
  },
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    component: () => import( '../views/About.vue')
  },
  {
    path: '/goods',
    name: 'Goods',
    component: () => import( '../views/Goods.vue')
  },
  {
	  path: '/details',
	  name: 'Details',
	  component: () => import( '../views/Details.vue')
  },
  {
    path:"/collect",
    name:"Collect",
    component: () => import( '../views/Collect.vue'),
    neta:{
      loginFlag:true
    }
  },
  {
    path:"/shopcart",
    name:"Shopcart",
    component: () => import( '../views/Shopcart.vue'),
    meta:{
      loginFlag:true
    }
  },
  {
    path:"/confimorder",
    name:"ConfimOrder",
    component: () => import( '../views/ConfimOrder.vue'),
  },
  {
    path:"/orders",
    name:"orders",
    component: () => import( '../views/orders.vue'),
  }

]

const originalPush =VueRouter.prototype.push
VueRouter.prototype.push=function push(location){
  return originalPush.call(this,location).catch(err=>err)
}

const router = new VueRouter({
  routes
})

import store from '../store/index'

//路由守卫
router.beforeEach((to,from,next)=>{
  if(to.meta.loginFlag&&!window.localStorage.getItem('user')){
    store.commit("setShowLogin",true)
    return next(false)
  }
  next()
})
export default router
